import psycopg2  
  
# 连接数据库  
conn = psycopg2.connect(  
    host="localhost",  
    port="5432",  
    database="postgres",  
    user="postgres",  
    password="123456"  
)  
  
# 创建游标  
cur = conn.cursor()  
  
# 查询users表  
cur.execute("SELECT * FROM users where username='dehong'")  
  
# 获取查询结果  
rows = cur.fetchall()  
  
# 打印查询结果  
for row in rows:  
    print(row)  
  
# 关闭游标和连接  
cur.close()  
conn.close()